package com.example.demo.controller;


import com.example.demo.Config.PageHelperConfig;
import com.example.demo.common.ResultBody;
import com.example.demo.common.response.BaseServiceResponse;
import com.example.demo.model.Product;
import com.example.demo.param.ProductParamVo;
import com.example.demo.service.ProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {
    @Resource
    ProductService productService;

    @RequestMapping(value = "/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE )
    public BaseServiceResponse<?> getProduct(@RequestBody ProductParamVo productParamVo) {
        try {
            PageHelper.startPage(productParamVo.getPageNum(), productParamVo.getPageSize());
            List<Product> list = productService.selectGetProductByCount();
            PageInfo pageInfo = new PageInfo(list, productParamVo.getPageSize());
            return new BaseServiceResponse<>(pageInfo,ResultBody.success,"success");
        }catch (Exception e){
            return null;
        }

    }
}
